'use strict'
const express = require('express')
let api = express()

function startHttpService(port = 5288) {
    api.listen(port, (err) => {
        if (!err) console.log('httpService Start')
    })
}
api.use(express.json())
api.use(express.urlencoded({ extended: true }))
//设置跨域请求头
api.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Credentials", "true");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});
//测试接口
api.get('/get', (req, res) => {
    res.send('getOk')
})
api.post('/post', (req, res) => {
    console.log(req.body)
    res.send('postOk')
})
module.exports = {startHttpService}